/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testing;

/**
 *
 * @author node1
 */
public class TestSyn1 {
  int taskID;

  public synchronized void performATask(int val) {
    taskID = val;
    print("before: " + taskID);
    try {
      Thread.sleep(4000);
    } catch (InterruptedException x) {
    }
    print("after: " + taskID);
  }

  public static void print(String msg) {
    System.out.println(Thread.currentThread().getName() + ": " + msg);
  }

  public static void main(String[] args) throws Exception{
    final TestSyn1 tus = new TestSyn1();

    Runnable runA = new Runnable() {
      public void run() {
        tus.performATask(1);
      }
    };

    Thread ta = new Thread(runA, "threadA");
    ta.start();

    Thread.sleep(2000);

    Runnable runB = new Runnable() {
      public void run() {
        tus.performATask(2);
      }
    };

    Thread tb = new Thread(runB, "threadB");
    tb.start();
  }    
}
